package com.jsnkj.basic.fragment.earnings

import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import com.jsnkj.basic.R
import com.jsnkj.basic.adapter.InvitingNewAdapter
import com.jsnkj.basic.databinding.FragmentInvitingNewBinding
import com.jsnkj.basic.mvvm.BaseMVVMActivity
import com.jsnkj.basic.mvvm.BaseMVVMFragment
import com.jsnkj.basic.util.ErrorResultUtil

//邀新奖励
class InvitingNewFragment : BaseMVVMFragment<FragmentInvitingNewBinding, InvitingNewViewModel>() {

    companion object {
        fun newInstance() = InvitingNewFragment()
    }

    override val layoutId: Int
        get() = R.layout.fragment_inviting_new


    var invitingNewAdapter: InvitingNewAdapter? = null


    override fun initView(savedInstanceState: Bundle?) {


        mVM.postHttpResult.observe(this) { entity ->

            //txt_aggregate_income
            mVDB.txtAggregateIncome.text = entity.getTotal_commissions()

            if (entity.getInvites().isNullOrEmpty()) {
                entity.setInvites(ArrayList())
            }
            invitingNewAdapter = InvitingNewAdapter(requireActivity(), entity.getInvites()!!)

            mVDB.txtError.visibility = View.GONE

            mVDB.rvInviting.apply {
                layoutManager =
                    LinearLayoutManager(requireActivity(), LinearLayoutManager.VERTICAL, false)
                adapter = invitingNewAdapter
                visibility = View.VISIBLE
                setFocusable(false);
            }
        }


        mVM.errorResult.observe(this) {
            ErrorResultUtil.errorResult(requireActivity() as BaseMVVMActivity<*, *>, it)

            mVDB.txtError.visibility = View.VISIBLE
            mVDB.rvInviting.visibility = View.GONE
        }

        mVM.postAppList()
    }

}